<?php

class EnterpriseUsersList extends UsersAdminAbstractList
{

    function __construct()
    {
        parent::__construct( 'user_enterprise', 10, '',
                array( 'name' => 1, 'fiscal_id' => 1 ) );
    }

    function crear()
    {
        $sql = 'INSERT INTO users (name,first_surname,second_surname,fiscal_id,username,password) VALUES (' . MyLink::quote( $_POST[ 'name' ] ) . ',' . MyLink::quote( $_POST[ 'first_surname' ] ) . ',' . MyLink::quote( $_POST[ 'second_surname' ] ) . ',' . MyLink::quote( $_POST[ 'fiscal_id' ] ) . ',' . MyLink::quote( $_POST[ 'username' ] ) . ',' . MyLink::quote( $_POST[ 'password' ] );
        MyLink::$default->execute( $sql );
        $id = MyLink::$default->insert_id;

        if ( $_POST[ 'admin' ] ) {
            Security::addResourceEdges( array( 'R_USR' => array( $id ) ),
                    'R_USR_ORG', $_SESSION[ 'organization' ] );
            Security::addResourceEdges( array( 'R_USR' => array( $id ) ),
                    'R_ADM_ORG', $_SESSION[ 'organization' ] );
            Security::addUserRoles( $id,
                    array( 'ADM_ORG' => array( $_SESSION[ 'organization' ] ) ) );
        } else {
            Security::addResourceEdges( array( 'R_USR' => array( $id ) ),
                    'R_USR_ORG', $_SESSION[ 'organization' ] );
        }
    }

}

?>
